<%
'赤金CMS www.cjAsp.com All Rights Reserved 
'文件名称：cache.inc
'作用：更新网站缓存

function updateCache(data)
	dim obj, result
	set obj = new cacheModel
	result = obj.update(data)
	set obj = nothing
	updateCache = result
end function

class cacheModel
	private rs, data, i

	'************************************************************
	'外部使用快捷方式
	'************************************************************
	public function update(data)
		select case lcase(data)
			case "genre" 	: genreCache()
			case "class" 	: classCache()
			case "allclass" : allClassCache()
			case "config" 	: configCache()
			case else
				genreCache()
				classCache()
				allClassCache()
				configCache()
		end select
		update = true
	end function
	
	'************************************************************
	'配置缓存
	'************************************************************
	public function configCache()
		set rs = db.exec("select configName,configValue from cj_config", 1)
		if not(rs.eof) then
			application.lock
			do until rs.eof
				application(cacheName & "_Config_" & rs(0)) = rs(1)
			rs.movenext : loop
			application.unLock
		end if
		set rs = nothing
		configCache = true
	end function

	'************************************************************
	'大类缓存
	'************************************************************
	public function genreCache()
		set rs = db.exec("select genreID,genreType,genreName,genreShortName,genreUnit,genreViewID from cj_genre where isStop=false Order By genreID", 2)
		if not(rs.eof) then
			data = rs.getString(,,"|||",vbCr,"") '第3参数：字段间分割，第4参数：行间分割
		end if
		rs.close : set rs = nothing
		if data <> "" then
			dim all, n, k
			n = split(data, vbCr) '分割读取的数据
			all = ""
			for i = 0 to ubound(n) - 1 '减掉1行
				k = split(n(i), "|||") '行数据
				app.setAppCache "genreInfo_" & k(0), n(i) '写入缓存
				all = all & k(0) & ","
			next
			if all <> "" then
				all = left(all, len(all) - 1)
				app.setAppCache "genreAll", all '所有大类ID 写入缓存
			end if
		end if
		genreCache = true
	end function

	'************************************************************
	'栏目缓存
	'************************************************************
	public function classCache()
		set rs = db.exec("select classID,genreID,className,classViewID,contentViewID from cj_class where isStop=false", 2)
		if not(rs.eof) then
			data = rs.getString(,,"|||",vbCr,"") '第3参数：字段间分割，第4参数：行间分割
		end if
		rs.close : set rs = nothing
		if data <> "" then
			dim n, k
			n = split(data, vbCr) '分割读取的数据
			for i = 0 to ubound(n) - 1 '减掉1行
				k = split(n(i), "|||") '行数据
				app.setAppCache "classInfo_" & k(0), n(i) '写入缓存
			next
		end if
		classCache = true
	end function

	'************************************************************
	'生成所有栏目缓存
	'所有栏目 classAll
	'大类ID下的栏目ID genreClass_" & 栏目ID
	'************************************************************
	public function allClassCache()
		dim all, rs1, n, id, data1
		all = ""
		data = ""
		set rs = db.exec("select genreID from cj_genre where isStop=false Order By genreID", 2)
		if not(rs.eof) then
			data = rs.getString(,,,",","") '第3参数：字段间分割，第4参数：行间分割
		end if
		rs.close : set rs = nothing
		if data <> "" then
			n = split(data, ",")
			for i = 0 to ubound(n) - 1
				id = n(i)
				data1 = ""
				set rs1 = db.exec("select classID from cj_class where isStop=false and genreID=" & id, 2)
				if not(rs1.eof) then
					data1 = rs1.getString(,,,",","")
				end if
				rs1.close : set rs1 = nothing
				all = all & data1
				if data1 <> "" then
					data1 = left(data1, len(data1) - 1)
				end if
				app.setAppCache "genreClass_" & id, data1
			next
		end if
		if all <> "" then
			all = left(all, len(all) - 1)
			app.setAppCache "classAll", all
		end if
		allClassCache = true
	end function

end class

%>